<?php

namespace App\Containers\AppSection\Signature\Models;

use App\Containers\AppSection\File\Models\File;
use App\Containers\AppSection\Profile\Models\Profile;
use App\Ship\Parents\Models\Model;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Подпись
 *
 * @property int $id Id
 * @property int $file_id Файл
 * @property int $profile_id Профиль
 * @property string $path путь
 * @property string $issuer
 * @property string $subject
 * @property Carbon $signing_time
 * @property string $version
 * @property string $serial_number
 * @property string $thumbprint
 * @property Carbon $valid_from
 * @property Carbon $valid_to
 * @property bool $is_private
 * @property bool $is_valid
 * @property Carbon $created_at Время создания
 * @property Carbon $updated_at Время обновления
 *
 * @property File $file Файл
 * @property Profile $profile Профиль
 *
 */
class Signature extends Model
{
    protected $fillable = [
        'file_id',
        'profile_id',
        'path',
        'issuer',
        'subject',
        'signing_time',
        'version',
        'serial_number',
        'thumbprint',
        'valid_from',
        'valid_to',
        'is_private',
        'is_valid',
    ];

    protected $dates = [
        'created_at',
        'updated_at',
        'signing_time',
        'valid_from',
        'valid_to',
    ];

    protected $casts = [
        'issuer' => 'json',
        'subject' => 'json',
    ];

    /**
     * A resource key to be used in the serialized responses.
     */
    protected string $resourceKey = 'Signature';


    /**
     * Файл
     * @return BelongsTo File
     */
    public function file(): BelongsTo
    {
        return $this->belongsTo(File::class, 'file_id', 'id');
    }

    /**
     * Профиль
     * @return BelongsTo Profile
     */
    public function profile(): BelongsTo
    {
        return $this->belongsTo(Profile::class, 'profile_id', 'id');
    }
}
